<template>
  <div>
    <div id="page">
      <!-- 头部 -->
      <header>
        <!-- <span class="iconfont">&#xe6bc;</span> -->
        <v-back></v-back>
        <h2>{{ goodInfo.goodsname }}</h2>
        <p>
          <span class="iconfont">&#xf0112;</span>
          <span class="iconfont">&#xe71e;</span>
          <i></i>
        </p>
      </header>
      <!-- 导航 -->
      <nav>
        <a href="">商品</a>
        <a href="">评价</a>
        <a href="">详情</a>
        <a href="">推荐</a>
      </nav>
      <!-- 主体 -->
      <main>
        <div class="banner">
          <img :src="$pre+goodInfo.img" alt="" />
        </div>
        <div class="content">
          <p class="price">
            <i>￥</i><em>{{ goodInfo.price }}</em
            ><del>￥{{ goodInfo.market_price }}</del
            ><span><b class="iconfont">&#xe60f;</b>收藏</span>
          </p>
          <h3>{{ goodInfo.goodsname }}</h3>
        </div>
        <div class="way">
          <p>
            <i>领券</i>
            <span>
              <em>
                <img src="../../assets/images/price_03.jpg" alt="" />
              </em>
              <em>
                <img src="../../assets/images/price_05.jpg" alt="" />
              </em>
              <em>
                <img src="../../assets/images/price_07.jpg" alt="" />
              </em>
            </span>
          </p>
          <p><i>分期</i><span>可选3/6/12期</span></p>
        </div>
        <p class="des" v-html="goodInfo.description"></p>
      </main>
      <!-- 底部 -->
      <footer>
        <p>
          <span><i class="iconfont">&#xe62d;</i>客服</span>
          <span><i class="iconfont">&#xe663;</i>店铺</span>
          <span><i class="iconfont">&#xe612;</i>购物车</span>
        </p>
        <p>
          <button @click="add()">加入购物车</button>
          <button>立即购买</button>
        </p>
      </footer>
    </div>
  </div>
</template>

<script>
import { getGoodsinfo, cartAdd } from "../../request/api.js";
export default {
  data() {
    return {
      goodInfo: {},
      userInfo: sessionStorage.getItem("token")
        ? JSON.parse(sessionStorage.getItem("token"))
        : {},
    };
  },
  methods: {
    add() {
      // 先判断用户是否登陆过
      if (this.userInfo.token) {
        //调接口
        cartAdd({
          uid: this.userInfo.uid,
          goodsid: this.goodInfo.id,
          num: 1,
        }).then(res=>{
          if(res.data.code==200){
            this.Toast.success("添加成功")
            this.$router.push("/index/cart")
          }
        });
      } else {
        this.Toast.fail("请先登录");
        this.$router.push("/login");
      }
    },
  },
  mounted() {
    getGoodsinfo(this.$route.query).then((res) => {
      this.goodInfo = res.data.list[0];
    });
  },
};
</script>

<style scoped>
html,
body,
#page {
  height: 100%;
}
#page {
  max-width: 7.5rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
header {
  height: 0.8rem;
  background: #ff6040;
  display: flex;
  color: #ffdfd8;
  padding: 0.3rem 0.12rem 0.12rem 0.33rem;
  align-items: center;
}
header h2 {
  font-size: 0.3rem;
  margin: 0 0.4rem 0 1.75rem;
  width: 3rem;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
header p {
  width: 1.72rem;
  height: 0.62rem;
  border: 1px solid #ff876c;
  border-radius: 0.31rem;
  line-height: 0.62rem;
  display: flex;
  justify-content: space-between;
  position: relative;
}
header p span {
  width: 0.86rem;
  text-align: center;
}
header p i {
  width: 1px;
  height: 0.37rem;
  background: #ff876c;
  position: absolute;
  left: 0.86rem;
  top: 0.12rem;
}
nav {
  padding: 0.2rem 0.74rem 0.17rem 0.68rem;
  background: linear-gradient(#ff6040, #ff8071);
  display: flex;
  justify-content: space-between;
  font-size: 0.26rem;
}
nav a {
  color: #fff;
}
main {
  flex: 1;
  overflow: auto;
}
main .banner img {
  width: 100%;
}
main .content {
  padding: 0 0.21rem 0.16rem 0.26rem;
  background: #fff;
  margin-bottom: 0.2rem;
}
main .content .price {
  font-size: 0.2rem;
  display: flex;
  align-items: center;
}
main .content .price i {
  color: #ff6040;
}
main .content .price em {
  color: #ff6040;
  margin: 0 0.13rem 0 0.09rem;
  font-size: 0.44rem;
}
main .content .price del {
  color: #999999;
  margin-right: 4.2rem;
}
main .content .price span {
  display: flex;
  align-items: center;
  flex-direction: column;
  color: #ff6444;
}
main .content h3 {
  font-size: 0.3rem;
  color: #333333;
  margin-bottom: 0.12rem;
}
main .content .text {
  color: #999999;
}
main .content .rate {
  width: 1.66rem;
  height: 0.32rem;
  background: #ff8066;
  color: #fff;
  font-size: 0.18rem;
  text-align: center;
  line-height: 0.32rem;
  margin: 0.25rem 0 0.2rem;
}
main .content .time {
  background: #f2f2f2;
  color: #999999;
  font-size: 0.18rem;
}
main .content .time a {
  color: #ff6040;
  font-size: 0.18rem;
}
main .way {
  background: #fff;
  padding-left: 0.21rem;
}
main .way p {
  height: 0.9rem;
  display: flex;
  align-items: center;
}
main .way p span {
  display: flex;
  align-items: center;
  width: 86%;
  height: 0.98rem;
  border-bottom: 1px solid #e6e6e6;
  color: #787878;
  font-size: 0.22rem;
}
main .way p span em {
  margin-right: 0.2rem;
}
main .way p span em img {
  width: 100%;
}
main .way p i {
  color: #333333;
  margin-right: 0.42rem;
  font-weight: bold;
  font-size: 0.22rem;
}
footer {
  display: flex;
  background: #fff;
  border-top: 1px solid #cccccc;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
}
footer p:nth-child(1) {
  width: 41%;
  height: 0.98rem;
  display: flex;
  padding: 0 0.42rem;
  box-sizing: border-box;
  justify-content: space-between;
  align-items: center;
}
footer p:nth-child(1) span {
  display: flex;
  flex-direction: column;
  font-size: 0.18rem;
  color: #444444;
  align-items: center;
}
footer p:nth-child(1) span i {
  font-size: 0.4rem;
  margin-bottom: 0.1rem;
  color: #333333;
}
footer p:nth-child(2) {
  display: flex;
  width: 59%;
}
footer p:nth-child(2) button {
  width: 50%;
  height: 0.98rem;
  text-align: center;
  line-height: 0.98rem;
  border: none;
}
footer p:nth-child(2) button:nth-child(1) {
  background: #ffcc66;
  font-size: 0.3rem;
  color: #663014;
  font-weight: bold;
}
footer p:nth-child(2) button:nth-child(2) {
  background: #ff6040;
  font-size: 0.3rem;
  color: #fff;
  font-weight: bold;
}
@media screen and (min-width: 320px) and (max-width: 375px) {
  .time {
    width: 7.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>